<?php include("src/addBusiness_cs.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href='css/coolMessage.css' type='text/css' rel='stylesheet' media='screen' />
<title>Add Business :: First United Services LLC</title>
<script language="javaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="javaScript" type="text/javascript" src="js/jquery.simplemodal.js"></script>
<script language="javaScript" type="text/javascript" src="js/coolMessage.js"></script>
<link rel="stylesheet" href="js/fancybox/fancy.css" type="text/css" media="screen">
<script type="text/javascript" src="js/fancybox/jquery.fancybox-1.0.0.js"></script>
<script language="javascript" type="text/javascript">

	$(document).ready(function() {
		$(".fancyto").fancybox({
				 'zoomSpeedIn': 700, //Provoca el efecto al abrirse
				 'zoomSpeedOut': 500, //Provoca el efecto al cerrarse.
				 'frameWidth': 450, // Ancho del reproductor.
				 'frameHeight': 150, // Alto del reproductor
				 'overlayShow': true, // Parámetro que sirve para definir si se muestra o no el fondo oscuro.
				 'overlayOpacity': 0.4 //Determina el nivel de opacidad del fondo.
		 });
		 

	});
	
	function showMessage(show_msg){
		switch(show_msg){
			case 1://error
				coolMessage('error',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case 2://alert
				coolMessage('alert',"<?php echo $_SESSION["msg_cool"];?>");
			break;
			
			case 3://information
				coolMessage('information',"<?php echo $_SESSION["msg_cool"];?>", function (){ window.location.href = '/listClient.php'});
			break;
			
			default:
				
			break;
		}
		return false;
	}
	
	function onlyNumbers(e)
	{
	   var key;
	   if(window.event)
		  key = window.event.keyCode;   //IE
	   else
		  key = e.which;                //firefox
	   if (!( (key >= 48 && key <= 57) || key ==8 || key ==9 || key ==0 || key ==46 ))
		  return false;
	   else
		  return true;
	}
	
	function validate(action){
		document.getElementById("action").value = action;//1: save, 2: save and continue.
		
		var msg = '';
		var cli_code = document.getElementById("cli_code").value;
		var bus_code = document.getElementById("bus_code").value;
		var use_code = document.getElementById("use_code").value;
		
		if(cli_code == '') 
			msg= msg+'- Please select a client.<br />';
				
		if(bus_code == '') 
			msg= msg+'- Please select a Business Type.<br />';
		
		if(use_code == '') 
			msg= msg+'- Please select a Adviser.<br />';
		
		if(msg == ''){
			document.getElementById('form').submit();
			return true;
		}
		else{
			coolMessage("alert", msg);
			return false;
		}		
	}
	
	function chargeBusinessType(bus_code){
		if ( bus_code == -1 )//document.getElementById("link_bank").click();			
			$("#link_business").trigger('click');
		else{
			jQuery.ajax({
			type: "POST",
			async : false,
			url: "ajaxChargeBusinessType.php",
			data: 'bus_code='+bus_code,
			success: function(result){
				if ( result == -1 )
					coolMessage("error", "An error ocurred loading Business Types.");
				}
			});
		}
		return false;
	}	
	
	function reloadBusiness(html_banks){
		document.getElementById("content_business").innerHTML = html_banks;
		$.fn.fancybox.close();
	}
	
	
	function showCoolMessage(msg, type){		
		if ( type == 1 ){
			$.fn.fancybox.close();
			coolMessage("error", msg);
		}
		return false;
	}	
	
</script>
</head>
<body>
<?php $item_select = 3; include("menu.php");?><br />
    <form name="form" id="form" method="post" action="">
    <input type="hidden" name="add" id="add" value="1"/>		
	<input type="hidden" name="action" id="action" value="1"/>
    <input type="hidden" name="case_code" id="case_code" value="<?php echo $case_code;?>" />
    <div class="content_grv">
        <a href="addBusinessType.php" class="fancyto" id="link_business"></a>
        <table width="90%" align="center" class="shadow">
            <tr>
                <td class="title">Business</td>
            </tr>
            <tr>
                <td>
                    <table class="tbl_form" align="center">                                                
                        <tr>
                            <td align="right" width="35%"><span class="lbl_gray">Client:</span></td>
                            <td width="1%">&nbsp;</td>
                            <td>
                            <?php if ($cli_code){?>
                            	<input type="hidden" name="cli_code" id="cli_code" value="<?php echo $cli_code;?>" />
                                <span class="lbl_black"><?php echo $cli_name.' '.$cli_lastname;?></span>
                            <?php }else{?>
                            	<select name="cli_code" id="cli_code" class="text_grv">
                                    <option value="" selected="selected" disabled="disabled">Select..</option>
                                    <?php 
									$countClient = count($listClients);
									for($i=0; $i < $countClient; $i++){
										if ( $listClients[$i]->cli_code == $cli_code )
											$selected = 'selected';
										else
											$selected = '';
									?>
                                    <option value="<?php echo $listClients[$i]->cli_code;?>" <?php echo $selected;?>><?php echo $listClients[$i]->cli_name." ".$listClients[$i]->cli_lastname;?></option>
                                    <?php }?>
								</select>
                            <?php }?>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" valign="top"><span class="lbl_gray">Case Number:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            	<input type="hidden" name="case_number" id="case_number" value="<?php echo $case_number;?>"  /> 
                            	<span class="lbl_black"><?php echo $case_number;?></span>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Business Type:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            <div id="content_business">
                            <select name="bus_code" id="bus_code" class="text_grv" onchange="javascript: chargeBusinessType(this.value);">
                                <option value="" selected="selected" disabled="disabled">Select..</option>
                                <?php 
								$countBusinessType = count ($listBusinessType);
								for($i=0; $i< $countBusinessType ;$i++) {
									if ( $listBusinessType[$i]->bus_code == $bus_code )
										$selected = 'selected';
									else
										$selected = '';
								?>
                                <option value="<?php echo $listBusinessType[$i]->bus_code;?>" <?php echo $selected;?>><?php echo $listBusinessType[$i]->bus_name;?></option>
                                <?php }?>
                                <option value="-1">Others..</option>
                            </select>
                            </div>
                            </td>
                        </tr>
         				<tr>
                            <td align="right"><span class="lbl_gray">Adviser:</span></td>
                            <td>&nbsp;</td>
                            <td>
                                <select name="use_code" id="use_code" class="text_grv">
                                    <option value="" selected="selected" disabled="disabled">Select..</option>
                                    <?php 
                                    $countAdvisers = count ($listAdvisers);
                                    for($i=0; $i< $countAdvisers ;$i++) {
										if ( $listAdvisers[$i]->use_code == $use_code )
											$selected = 'selected';
										else
											$selected = '';
									?>
                                    <option value="<?php echo $listAdvisers[$i]->use_code;?>" <?php echo $selected;?>><?php echo $listAdvisers[$i]->use_name." ".$listAdvisers[$i]->use_lastname;?></option>
                                    <?php }?>
                                </select>
                            </td>
                       </tr>
                        <tr>
                            <td align="right"><span class="lbl_gray">Balance:</span></td>
                            <td>&nbsp;</td>
                            <td>
                            <?php if ( $countPaymentDetail ){?>
                            <input type="hidden" name="case_balance" id="case_balance" value="<?php echo $case_balance;?>" />
                            <span class="lbl_black"><?php echo $case_balance;?></span>
                            <?php }else{?>
                            <input type="text" name="case_balance" id="case_balance" value="<?php echo $case_balance;?>" class="text_grv" size="20" maxlength="19" onKeyPress="return onlyNumbers(event)"/>
                            <?php }?>
                            </td>
                        </tr>
                        <tr <?php if ( ! $case_code ){?> style=" display:none" <?php }?>>
                            <td align="right"><span class="lbl_gray">Approved:</span></td>
                            <td>&nbsp;</td>
                            <td><input type="checkbox" name="case_approved" id="case_approved" value="1" <?php if ( $case_approved){?> checked="checked"<?php }?>/></td>
                        </tr>
                        <tr>
                            <td align="right" valign="top"><span class="lbl_gray">Notes:</span></td>
                            <td>&nbsp;</td>
                            <td><textarea name="case_comment" id="case_comment" class="text_grv" cols="40" rows="7"><?php echo $case_comment;?></textarea></td>
                        </tr>
                        <tr><td colspan="3" align="center">&nbsp;</td></tr>
                        <tr>
                            <td colspan="3" align="center">
                                <input type="button" class="button_grv" value="Save" onclick="javascript: return validate(1);" />
                                <?php if ( ! $case_code ){?>
                                <input type="button" class="button_grv" value="Save and continue" onclick="javascript: return validate(2);" />
                                <?php }?>
                                <input type="reset" value="Reset" class="button_grv_cancel"/>
                                <input type="button" class="button_grv_cancel" value="Cancel" onClick="javascript: window.location.href='listBusiness.php';" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>    
</body>
</html>
<?php include('divscoolmessage.php');?>